/**
 * 
 */
package com.redside.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * @author PCHAPMAN
 * 
 */
@Entity
@Table(name = "parent_business")
public class ParentBusiness extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1516621218669149856L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "parent_id")
    private Long id;

    @Column(name = "contact_first_name", length = 50)
    private String contactFirstName;

    @Column(name = "contact_last_name", length = 50)
    private String contactLastName;

    @Column(name = "contact_title", length = 50)
    private String contactTitle;

    @Column(name = "contact_email", unique = true, length = 50)
    private String contactEmail;

    @Column(name = "contact_phone", length = 14)
    private String contactPhone;

    @Column(name = "contact_phone_ext", length = 6)
    private String contactPhoneExt;

    @Column(name = "business_name", nullable = false, length = 50)
    private String businessName;

    @Embedded
    private Address address = new Address();

    @Column(name = "business_phone", length = 14)
    private String businessPhone;

    @Column(name = "business_phone_ext", length = 6)
    private String businessPhoneExt;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id")
    private List<Business> businesses = new ArrayList<Business>(0);

    public ParentBusiness() {
    }

    /**
     * @param contactFirstName
     * @param contactLastName
     * @param contactTitle
     * @param contactEmail
     * @param contactPhone
     * @param contactPhoneExt
     * @param businessName
     * @param businessAddress1
     * @param businessAddress2
     * @param businessCity
     * @param businessZip
     * @param countyLkpId
     * @param stateLkpId
     * @param businessPhone
     * @param businessPhoneExt
     */
    public ParentBusiness(String contactFirstName, String contactLastName,
            String contactTitle, String contactEmail, String contactPhone,
            String contactPhoneExt, String businessName, String address1,
            String address2, String city, String zip,
            String zipExt, String stateId, String phone,
            String phoneExt) {
        super();
        this.contactFirstName = contactFirstName;
        this.contactLastName = contactLastName;
        this.contactTitle = contactTitle;
        this.contactEmail = contactEmail;
        this.contactPhone = contactPhone;
        this.contactPhoneExt = contactPhoneExt;
        this.businessName = businessName;
        this.address.setAddress1(address1);
        this.address.setAddress2(address2);
        this.address.setCity(city);
        this.address.setPostalCode(zip);
        this.address.setPostalCodeExt(zipExt);
        this.address.setStateId(stateId);
        this.businessPhone = phone;
        this.businessPhoneExt = phoneExt;
    }

    
    /**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the contactFirstName
	 */
	public String getContactFirstName() {
		return contactFirstName;
	}

	/**
	 * @param contactFirstName the contactFirstName to set
	 */
	public void setContactFirstName(String contactFirstName) {
		this.contactFirstName = contactFirstName;
	}

	/**
	 * @return the contactLastName
	 */
	public String getContactLastName() {
		return contactLastName;
	}

	/**
	 * @param contactLastName the contactLastName to set
	 */
	public void setContactLastName(String contactLastName) {
		this.contactLastName = contactLastName;
	}

	/**
	 * @return the contactTitle
	 */
	public String getContactTitle() {
		return contactTitle;
	}

	/**
	 * @param contactTitle the contactTitle to set
	 */
	public void setContactTitle(String contactTitle) {
		this.contactTitle = contactTitle;
	}

	/**
	 * @return the contactEmail
	 */
	public String getContactEmail() {
		return contactEmail;
	}

	/**
	 * @param contactEmail the contactEmail to set
	 */
	public void setContactEmail(String contactEmail) {
		this.contactEmail = contactEmail;
	}

	/**
	 * @return the contactPhone
	 */
	public String getContactPhone() {
		return contactPhone;
	}

	/**
	 * @param contactPhone the contactPhone to set
	 */
	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	/**
	 * @return the contactPhoneExt
	 */
	public String getContactPhoneExt() {
		return contactPhoneExt;
	}

	/**
	 * @param contactPhoneExt the contactPhoneExt to set
	 */
	public void setContactPhoneExt(String contactPhoneExt) {
		this.contactPhoneExt = contactPhoneExt;
	}

	/**
	 * @return the businessName
	 */
	public String getBusinessName() {
		return businessName;
	}

	/**
	 * @param businessName the businessName to set
	 */
	public void setBusinessName(String businessName) {
		this.businessName = businessName;
	}

	/**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * @return the businessPhone
	 */
	public String getBusinessPhone() {
		return businessPhone;
	}

	/**
	 * @param businessPhone the businessPhone to set
	 */
	public void setBusinessPhone(String businessPhone) {
		this.businessPhone = businessPhone;
	}

	/**
	 * @return the businessPhoneExt
	 */
	public String getBusinessPhoneExt() {
		return businessPhoneExt;
	}

	/**
	 * @param businessPhoneExt the businessPhoneExt to set
	 */
	public void setBusinessPhoneExt(String businessPhoneExt) {
		this.businessPhoneExt = businessPhoneExt;
	}

	/**
	 * @return the businesses
	 */
	public List<Business> getBusinesses() {
		return businesses;
	}

	/**
	 * @param businesses the businesses to set
	 */
	public void setBusinesses(List<Business> businesses) {
		this.businesses = businesses;
	}

	public void addBusiness(Business business){
        List<Business> businesses = this.getBusinesses();
        if(businesses == null){
            businesses=new ArrayList<Business>();
        }
        businesses.add(business);
        this.setBusinesses(businesses);
    }

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof ParentBusiness)) {
			return false;
		}
		ParentBusiness rhs = (ParentBusiness) object;
		return new EqualsBuilder().append(this.id, rhs.id).append(
				this.businessName, rhs.businessName).append(this.contactPhone,
				rhs.contactPhone).append(this.businessPhone, rhs.businessPhone)
				.append(this.contactLastName, rhs.contactLastName).append(
						this.address, rhs.address).append(this.contactPhoneExt,
						rhs.contactPhoneExt).append(this.contactEmail,
						rhs.contactEmail).append(this.contactTitle,
						rhs.contactTitle).append(this.contactFirstName,
						rhs.contactFirstName).append(this.businessPhoneExt,
						rhs.businessPhoneExt).append(this.businesses,
						rhs.businesses).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(431485353, 1937919439).append(this.id)
				.append(this.businessName).append(this.contactPhone).append(
						this.businessPhone).append(this.contactLastName)
				.append(this.address).append(this.contactPhoneExt).append(
						this.contactEmail).append(this.contactTitle).append(
						this.contactFirstName).append(this.businessPhoneExt)
				.append(this.businesses).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(
				"contactTitle", this.contactTitle).append("businesses",
				this.businesses).append("contactPhone", this.contactPhone)
				.append("contactFirstName", this.contactFirstName).append(
						"contactEmail", this.contactEmail).append(
						"contactPhoneExt", this.contactPhoneExt).append(
						"businessName", this.businessName).append(
						"contactLastName", this.contactLastName).append(
						"businessPhone", this.businessPhone).append(
						"businessPhoneExt", this.businessPhoneExt).append("id",
						this.id).append("address", this.address).toString();
	}
    


}
